package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.*;
import com.qfedu.openplateform.manager.service.ApiSystemparamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sys/systemparaters")
public class ApiSystemparamController {
    @Autowired
    private ApiSystemparamService aSS;

    @RequestMapping("/table")
    public TableData table(int page, int limit,ApiSystemparam apiSystemparam) {
        TableData tableData = new TableData<>();
        PageHelper.startPage(page, limit);
        List<ApiSystemparam> allAS = aSS.findAllAS(apiSystemparam);
        PageInfo pageInfo = new PageInfo(allAS);
        tableData.setCount(pageInfo.getTotal());
        tableData.setData(allAS);
        return tableData;
    }

    @RequestMapping("/del")
    public AjaxMessage deleteRecharge(IdList ids) {
        AjaxMessage ajaxMessage = new AjaxMessage();
        int i = aSS.delASById(ids.getIds());
        if (i == 1) {
            ajaxMessage.setStatus(true);
            return ajaxMessage;
        } else {
            ajaxMessage.setStatus(false);
            ajaxMessage.setMessage("删除失败！");
            return ajaxMessage;
        }
    }

    @RequestMapping("/add")
    public AjaxMessage addRecharge(ApiSystemparam apiSystemparam) {
        AjaxMessage ajaxMessage = new AjaxMessage();
        int i = aSS.addAS(apiSystemparam);
        if (i == 1) {
            ajaxMessage.setStatus(true);
            return ajaxMessage;
        } else {
            ajaxMessage.setMessage("添加失败！");
            return ajaxMessage;
        }
    }

    @RequestMapping("/update")
    public AjaxMessage updateRecharge(ApiSystemparam apiSystemparam) {
        AjaxMessage ajaxMessage = new AjaxMessage();
        int i = aSS.updateAS(apiSystemparam);
        if (i == 1) {
            ajaxMessage.setStatus(true);
            return ajaxMessage;
        } else {
            ajaxMessage.setMessage("修改失败！");
            return ajaxMessage;
        }
    }
}
